﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Collections.Generic;

namespace SilverApp.ViewModel
{
    public class FriendsViewModel : ViewModelBase
    {
        private ObservableCollection<LiveService.User>  friendsCollection;
        //private LiveService.LServiceClient              sclient;

        public FriendsViewModel(LiveService.User currentUser)
        {
            try 
            {
                this.friendsCollection = new ObservableCollection<LiveService.User>();
                //this.Sclient = new LiveService.LServiceClient();
                this.initUserFriends(currentUser);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

       /* public LiveService.LServiceClient Sclient
        {
            get { return this.sclient;  }
            set { this.sclient = value; }
        }*/

        public void initUserFriends(LiveService.User currentUser)
        {
            try
            {
                this.Sclient.getUserFriendsCompleted += new EventHandler<LiveService.getUserFriendsCompletedEventArgs>(initUserFriendsCompleted);
                this.Sclient.getUserFriendsAsync(currentUser.id);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        private void initUserFriendsCompleted(object sender, LiveService.getUserFriendsCompletedEventArgs e)
        {
            try
            {
                List<LiveService.User> xfriends = e.Result;

                foreach (LiveService.User auser in xfriends) {
                    this.friendsCollection.Add(auser);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}
